/**
 *
 * require.js的启动文件，main.js
 * 所有的文件都在这里被启动。
 * */
//各依赖包路径的配置


require.config({
    //预先指定需要加载的路径
    paths: {
        
        //路径的后缀按照require写法，省略.js
        
        world:   "../../Engine/3d/index/world",
        index:   "../../Engine/3d/index/newIndex",
        
        
        inherit: "../../Engine/3d/Plug-in/Inherit",
        tween: "../../Engine/3d/Plug-in/Tween",
        CanvasRenderer: "../../Engine/3d/Plug-in/CanvasRenderer",
        RaytracingRenderer: "../../Engine/3d/Plug-in/RaytracingRenderer",
        Projector: "../../Engine/3d/Plug-in/Projector",
        
        //八叉树搜索
        Octree: "../../Engine/3d/Plug-in/Octree",
        
        //鹰眼API
        hawkeye: "../../Engine/3d/Hawkeye/hawkeye",
        
        
        data: "../../Engine/3d/datalist/data",
        htmlDom: "../../Engine/3d/datalist/htmlDom",
        
        //模型加载类
        mtl: "../../Engine/3d/Plug-in/MTLLoader",
        obj: "../../Engine/3d/Plug-in/OBJLoader",
        objmodel: "../../Engine/3d/Plug-in/objmodel",
        OBJExporter: "../../Engine/3d/Plug-in/OBJExporter",
        GLTF: "../../Engine/3d/Plug-in/GLTFLoader",
        DAE: "../../Engine/3d/Plug-in/ColladaLoader",
        
        
        //控制类
        OrbitControls:   "../../Engine/3d/controls/OrbitControls",
        PointerLockControls: "../../Engine/3d/controls/PointerLockControls",
        cameraControl: "../../Engine/3d/controls/cameraControl",
        cameraMark: "../../Engine/3d/controls/cameraMark",
        transform: "../../Engine/3d/controls/TransformControls",
        editor: "../../Engine/3d/controls/EditorControls",
        
        
        //缓存类
        indexedDB: "../../Engine/3d/cache/indexedDB",
        cachemodel: "../../Engine/3d/cache/cacheModel",
        cacheData: "../../Engine/3d/cache/cacheData",
        
        
        //拾取类
        pick: "../../Engine/3d/operation/Pick",
        
        //剖切类
        cliping: "../../Engine/3d/operation/Cliping",
        material: "../../Engine/3d/operation/Material",
        
        //模型显隐类
        ShowOpacity:"../../Engine/3d/operation/ShowOpacity",
        
        //事件驱动器
        Event:"../../Engine/3d/operation/Event",
        
        //模型属性添加
        AddAttr:"../../Engine/3d/operation/addAttribute",
        
        //分解模型类
        Disassemble:"../../Engine/3d/operation/Disassemble",
        
        //框选模块
        Region: "../../Engine/3d/operation/Region",
        
        //鼠标事件
        mouseEvent:"../../Engine/3d/operation/mouseEvent",
        
        
        //ajax请求
        ajax: "../../Engine/3d/API/ajax",
        
        
        //输出数据文件
        flie: "../../Engine/3d/API/downFile",
        
        //IFC解析
        IFCparse: "../../Engine/3d/draw/parseIFC",
        
        //GEO解析
        GEOparse: "../../Engine/3d/draw/parseGeoJson",
        
        //GLTF解析
        
        
        //测量类
        Measure: "../../Engine/3d/draw/measure",
        
        //文字类
        text: "../../Engine/3d/draw/text",
        
        //标记类
        Signer: "../../Engine/3d/draw/signer",
        
        
        //相机缓动动画
        CameraMove: "../../Engine/3d/animation/CameraMove",
        
        /*
        *
        * 页面样式
        *
        * 侧栏+底部按钮+各个小模块
        *
        * */
        jquery:                 "../../Module/js/common/jquery-1.11.0.min",
        jqueryUI:               "../../Module/js/common/jquery-ui.min",
        draggabilly:            "../../Module/js/common/draggabilly.pkgd.min",
        angular:                "../../Module/js/common/angular.1.4.6.min",
        commonLet:              "../../Module/js/common/commonLet",
        
        pageCss:                "../../Module/js/pageCss",
        angularModule:          "../../Module/js/angularModule",
        
        pageInit:               "../../Module/js/pageInit",
        ngModule:               "../../Module/js/angular/ngModule",
        ngController:           "../../Module/js/angular/ngController",
        ngDiSlider:             "../../Module/js/angular/ngDirective.slider",
        ngDiSliderContent:      "../../Module/js/angular/ngDirective.slider.content",
        ngDiBottom:             "../../Module/js/angular/ngDirective.bottom",
        ngDiBottomContent:      "../../Module/js/angular/ngDirective.bottom.content",
        ngDiCanvas:             "../../Module/js/angular/ngDirective.canvas",
        ngDiDrag:               "../../Module/js/angular/ngDirective.drag",
        ngDiDragProperty:       "../../Module/js/angular/ngDirective.drag.property",
        ngDiDragStructure:      "../../Module/js/angular/ngDirective.drag.structure",
        ngDiDragEyesmark:       "../../Module/js/angular/ngDirective.drag.eyesmark",
        ngDiDragSearch:         "../../Module/js/angular/ngDirective.drag.search",
        ngDiDragSign:           "../../Module/js/angular/ngDirective.drag.sign",
        ngDiDragSection:        "../../Module/js/angular/ngDirective.drag.section",
        ngDiDragLocation:       "../../Module/js/angular/ngDirective.drag.location",
        ngDiDragResolve:        "../../Module/js/angular/ngDirective.drag.resolve",
        ngDiDragSetting:        "../../Module/js/angular/ngDirective.drag.setting",
        
        /*
        *
        * 公共配置文件
        *
        * */
        config:"config",

    },
    shim: {
        "draggabilly": {
            deps: ["jquery"]
        }
    }
});

//函数启动装置

require([
    "ajax",
], function (Ajax) {
    window.apiInit = function (divId, userId, modelId) {
            window.initsObj = {
            tables : []
        };
        if(divId == undefined || userId == undefined || modelId == undefined){
           alert("参数不能为空，请传入对应的参数：divId，userId,modelId");
            return;
        }else{
            var modelParams = {};
            modelParams.divId =divId;
            modelParams.userId = userId;
            if(typeof (modelId)!=="object"){
                modelParams.modelId = [modelId];
            }else{
                modelParams.modelId = modelId;
            }
        }
        for(var kl = 0; kl<modelParams.modelId.length;kl++){
            var indexObj = {
                    name:"ModelTable"+kl,              //存储空间表的名字
                    keypath:'id'//主键
                };
            initsObj.tables.push(indexObj);
        }
        require(["index", "pageCss", "commonLet", "tween", "Octree",
            "transform", "editor", "RaytracingRenderer", "OBJExporter",
            "mouseEvent", "Event"], function (API, pageCss, commonLet) {
            // 配置公共资源路径
            commonLet.USERID = commonLet.getParam(modelParams.userId);
            commonLet.MODELID = commonLet.getParam(modelParams.modelId);
            window.Model = API;
            window.pageCss = pageCss;
            Model.inStart = function (id) {
                var bimView = new pageCss();
                bimView.init(id);
                var angularScope = new bimView.angularScope();
                angularScope.initCanvas(id, function () {
                    initsObj.start = Model.start("Canvas");
                    for(var im = 0; im < modelParams.modelId.length;im++){
                        var user = modelParams.userId;
                        var model = modelParams.modelId[im];
                        Ajax.json({
                            url: "http://192.168.2.235:8086/model/total_geometry?userId=" + user + "&&modelId=" + model + "&callback=loader",
                            // url: "http://106.14.208.37:8086/model/total_geometry?userId=" + user + "&&modelId=" + model + "&callback=loader",
                            id: "v"+im,
                            number: im
                        },"loader",function(mol){
                            var data = mol.data;
                            var conf={};
                            conf.path = data.path;
                            conf.Canvas = data.Canvas;
                            conf.module = data.module;
                            var len = conf.Canvas.model.total-1;
                            var bros = {};
                            var path = [];
                            var model = {};
                            for (; len > -1; len--) {
                                var reference = conf.Canvas.model.reference;
                                model = {
                                    reference: reference,
                                    url: conf.path.AJAXURL + conf.Canvas.model.url + len + "&page=" + conf.Canvas.model.page + "&" + conf.Canvas.model.callback,
                                    talbe: conf.Canvas.model.talbe + len,
                                    model: {
                                        scale: 1,
                                        position: new THREE.Vector3(),
                                        rotation: new THREE.Vector3()
                                    },
                                    target:mol.id
                    
                                };
                                path.push(model);
                            }
                            bros.path = path;
                            bros.tableN = mol.number;
                            bros.index = conf.Canvas.model.talbe;
                            initsObj.start.load(bros);
                        })
                    }
                });
            };
            Model.inStart(modelParams.divId);
        });
    };
    // apiInit('container',"5c99d46eac3a071bbb0921d1",[
    //     "a1d16b10-5076-11e9-90a6-5be9702f719a",
    //     "d24a7000-5109-11e9-ba75-8d55b47520d8",
    //     "0b97eea0-510a-11e9-ba75-8d55b47520d8",
    //     "0b97eea0-510a-11e9-ba75-8d55b47520d8",
    //     "07495500-510a-11e9-ba75-8d55b47520d8"]);
    // apiInit('container',"5c999fda59de8e6d45bbe18c",[
    //    "354e6270-514a-11e9-9612-474953d8c666",
    //    "8de314d0-514a-11e9-9612-474953d8c666",
    // ]);
});